﻿var SiteController = Class.create({

    initialize: function (selector) {
        this.root = jQuery(selector);
        this.root.disableSelection();
        this.facebookbutton = jQuery('<div class="fb-like" data-href="https://www.facebook.com/www.adventureplus.bg" data-send="false" data-width="300" data-show-faces="true" data-font="verdana"></div>');
        this.root.prepend(this.facebookbutton);

        this.root.append('<div id="slider"></div>');
        this.slider = new SliderControl.Slider('#slider');
        this.packageHolidays = [];
        this.excursions = [];
        this.cruises = [];
    },

    addPackageHolliday: function (params) {

        var newPackageHolliday = new OffersNS.PackageHoliday(params);

        this.packageHolidays.push(newPackageHolliday);
        this.slider.addOffer(newPackageHolliday, newPackageHolliday.id);

        return newPackageHolliday;
    },

    addExcursion: function (params) {

        var newExcursion = new OffersNS.Excursion(params);

        this.excursions.push(newExcursion);
        this.slider.addOffer(newExcursion, newExcursion.id);

        return newExcursion;
    },

    addCruise: function (params) {

        var newCruise = new OffersNS.Cruise(params);

        this.cruises.push(newCruise);
        this.slider.addOffer(newCruise, newCruise.id);

        return newCruise;
    },

    render: function () {
        this.slider.render();
        this.renderTabs();
    },

    renderTabs: function () {
        var i = 0;
        var tabsDiv = jQuery(
            '<div id="tabs">\
                <ul>\
                    <li><a href="#holiday-tab" data-id="holiday-link-tab">Holidays</a></li>\
                    <li><a href="#excursion-tab" data-id="excursion-link-tab">Excursions</a></li>\
                    <li><a href="#cruise-tab" data-id="cruise-link-tab">Cruises</a></li>\
                </ul>\
            </div>');
        var holidayTab = jQuery('<div id="holiday-tab"></div>');
        tabsDiv.append(holidayTab);

        for (i = 0; i < this.packageHolidays.length; i++) {
            var holiday = this.packageHolidays[i].render();
            holidayTab.append(holiday);
        }

        var excursionTab = jQuery('<div id="excursion-tab"></div>');
        tabsDiv.append(excursionTab);

        for (i = 0; i < this.excursions.length; i++) {
            var excursion = this.excursions[i].render();
            excursionTab.append(excursion);
        }

        var cruiseTab = jQuery('<div id="cruise-tab"></div>');
        tabsDiv.append(cruiseTab);

        for (i = 0; i < this.cruises.length; i++) {
            var cruise = this.cruises[i].render();
            cruiseTab.append(cruise);
        }

        this.root.append(tabsDiv);
        $('#tabs').tabs();
    }
});